set more off 

use "ssi october 2012", clear

merge 1:1 svid using "ssi october 2012 wave 2"

keep if _m == 3

keep if independent == 0


foreach x in predict_obama {
	su `x', det
}


gen y = change_eco2 - change_eco


foreach x in expectwin predict_obama {
	su `x'
	replace `x' = (`x' - r(min))/(r(max) - r(min))
}


gen demXwin = democrat*predict_winner
gen demXvoteshare = democrat*predict_obama

label variable predict_winner "Prediction"
label variable predict_obama "Prediction"
label variable demXwin "Dem X prediction"
label variable demXvoteshare "Dem X prediction"

eststo clear

local controls info_scale SC BA PG income turnout age female black other

reg y `controls' predict_obama predict_winner republican
keep if e(sample)

eststo, title("Winner prediction"): xi: reg y republican , robust
eststo, title("Winner prediction"): xi: reg y republican `controls', robust

gen predict = predict_winner
gen demXpredict = predict*republican

eststo, title("Winner prediction"): xi: reg y republican predict demXpredict, robust
eststo, title("Winner prediction"): xi: reg y republican predict demXpredict `controls', robust

drop demXpredict predict
gen predict = predict_obama
gen demXpredict = republican*predict
eststo, title("Voteshare prediction"): xi: reg y republican predict demXpredict, robust
eststo, title("Winner prediction"): xi: reg y republican predict demXpredict `controls', robust

label variable predict "Prediction"
label variable demXpredict "Rep X prediction"

#delimit;

esttab 
	using "tableA3.tex"
	,
		replace
		booktabs
		cells(b(fmt(2)) se(par))
		collabels(none)
		nomtitles
		label  
		nogap
		mgroups("Baseline" "X winner prediction" " X voteshare prediction", pattern(1 0 1 0 1 0)
			prefix(\multicolumn{@span}{c}{) suffix(})
			span erepeat(\cmidrule(lr){@span}))	
		stats(N, label("Observations") fmt(%20.0fc))
		width(\textwidth)
		order(republican predict demXpredict)
		;
	
#delimit cr

shell "tabler.sh" "table A3.tex" "Change in economic perceptions" " "

